package zut.edu.cn.concertticketmanagementsystem.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import zut.edu.cn.concertticketmanagementsystem.entity.Ticket;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

public interface TicketDao extends JpaRepository<Ticket,Integer>{

      @Autowired
      Ticket t=new Ticket();
      /*
         根据歌手名字查找票情况
       */
      @Query(value = "SELECT * FROM ticket where t_singername=?1", nativeQuery = true)
      List<Ticket> findByT_singername(String singername);

      /*
         根据地址查找可看的演唱会
       */
      @Query(value = "SELECT * FROM ticket where t_address like %?1%",nativeQuery = true)
      List<Ticket> findAllByT_addressLike(String address);

      /*
        查找所有的票
       */
      @Query(value="SELECT * FROM ticket where t_id=?1",nativeQuery = true)
      Ticket findAllById(int t_id);

      /*
      查找上架票
       */
      @Query(value = "select * from ticket where t_type='已上架'",nativeQuery = true)
      List<Ticket> findAllByT_type();

      /*
         上架更新
       */
      @Modifying
      @Transactional
      @Query(value = "update ticket SET t_type='已上架' where t_id=?1",nativeQuery = true)
      int updateonT_type(int t_id);

      /*
         下架更新
       */
      @Modifying
      @Transactional
      @Query(value = "update ticket SET t_type='已下架' where t_id=?1",nativeQuery = true)
      int updateoffT_type(int t_id);

}
